const CracoLessPlugin = require('craco-less');
const CracoAntDesignPlugin = require('craco-antd');
const path = require('path');
const pathResolve = (pathUrl) => path.join(__dirname, pathUrl);
const { loaderByName, whenDev } = require('@craco/craco');
module.exports = {
	webpack: {
		alias: {
			'@@': pathResolve('.'),
			'@': pathResolve('src'),
			'@assets': pathResolve('src/assets'),
			'@common': pathResolve('src/common'),
			'@components': pathResolve('src/components'),
			'@hooks': pathResolve('src/hooks'),
			'@pages': pathResolve('src/pages'),
			'@store': pathResolve('src/store'),
			'@utils': pathResolve('src/utils')
		},
	},
	eslint: {
		enable: false /* (default value) */,
		mode: 'extends' /* (default value) */ || 'file',
		configure: {
			/* Any eslint configuration options: https://eslint.org/docs/user-guide/configuring */
		},
		// 配置全局变量
		globals: {
			TCPlayer: 'readonly'
		}
		// configure: (eslintConfig, { env, paths }) => { return eslintConfig; },
		// pluginOptions: { /* Any eslint plugin configuration options: https://github.com/webpack-contrib/eslint-webpack-plugin#options. */ },
		// pluginOptions: (eslintOptions, { env, paths }) => { return eslintOptions; }
	},
	plugins: [
		{
			plugin: CracoLessPlugin,
			// plugin: CracoAntDesignPlugin,
			options: {
				lessLoaderOptions: {
					lessOptions: {
						// modifyVars: { '@primary-color': '#1DA57A' },
						javascriptEnabled: true
					}
				}
				// 这里的配置并不起作用
				// modifyLessModuleRule(lessModuleRule, context) {
				// 	// Configure the file suffix
				// 	lessModuleRule.test = /\.m\.less$/;
				// 	// Configure the generated local ident name.
				// 	const cssLoader = lessModuleRule.use.find(loaderByName('css-loader'));
				// 	cssLoader.options.modules = {
				// 		localIdentName: '[local]_[hash:base64:5]'
				// 	};

				// 	return lessModuleRule;
				// }
			}
		},
	],
	babel: {
		// 支持装饰器模式语法
		plugins: [ [ '@babel/plugin-proposal-decorators', { legacy: true } ] ]
	},
	//  开发服务
	devServer: {
		hot: true,
		proxy: {
			// 代理地址
			'/api': {
				target: 'http://localhost:9000',
				changeOrigin: true,
				pathRewrite: {
					'^/api': ''
				}
			}
		}
	}
};
